<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>前端用户封停列表</title>
    <script src="/jquery/jquery-3.2.1.min.js"></script>
    <script src="/layui/layui.js"></script>
    <link rel="stylesheet" href="/layui/css/layui.css"/>
    <link rel="stylesheet" href="/css/usermodule/user-list.css"/>
</head>
<body>
    <div class="layui-row" >
        <div class="layui-col-md11">
            <div class="layui-card headerCenter">
                <div class="layui-card-header backColor">
                    用户封停列表
                    <div class="btnRight" style="margin-bottom: 10px">
                        <button onclick="refresh()" type="button" class="layui-btn layui-btn layui-btn-sm">
                            <i class="layui-icon layui-icon-refresh-1"></i>
                            刷新
                        </button>
                        <button onclick="backOff()" type="button" class="layui-btn layui-btn layui-btn-sm">
                            <i class="layui-icon layui-icon-return"></i>
                            返回
                        </button>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <!--筛选查询-->
    <div class="layui-row">
        <div class="layui-col-md11">
            <div class="layui-card headerCenter">
                <div class="layui-card-header backColor">
                    <i class="layui-icon">&#xe615;</i>
                    筛选查询
                    <button onclick="accurate()" class="btnRight layui-btn layui-btn-sm">
                        高级检索
                    </button>
                </div>
                <div class="layui-card-body">
                    <form class="layui-form" id="myFrom">
                        <div class="layui-form-item">
                            <div class="floa">
                                <label class="layui-form-label fontsize" >用户账号：</label>
                                <div class="layui-input-inline" style="margin-right: -30px; padding-right: -30px">
                                    <input type="text" name="account" required lay-verify="required" placeholder="用户账号" autocomplete="off" class="layui-input inp">
                                </div>
                            </div>
                            <div class="floa">
                                <label class="layui-form-label fontsize">用户昵称：</label>
                                <div class="layui-input-inline fontsize inp">
                                    <input type="text" name="nickname" required lay-verify="required" placeholder="用户昵称" autocomplete="off" class="layui-input inp">
                                </div>
                            </div>

                            <label class="layui-form-label fontsize">封停天数：</label>
                            <div class="layui-input-inline">
                                <select name="days" lay-verify="filter" lay-filter="filter">
                                    <option value="">请选择封停天数</option>
                                    <option value="7">7天</option>
                                    <option value="10">10天</option>
                                    <option value="15">15天</option>
                                    <option value="30">30天</option>
                                </select>
                            </div>

                            <span style="float:right;">
                                    <button onclick="selProduct()" type="button" class="layui-btn layui-btn layui-btn-sm">
                                        <i class="layui-icon layui-icon-search"></i> 搜索
                                    </button>
                                    <button onclick="refresh()" type="button" class="layui-btn layui-btn-warm layui-btn layui-btn-sm">
                                        <i class="layui-icon layui-icon-refresh-1"></i> 重置
                                    </button>
                                </span>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
    <div class="layui-row">
        <div class="layui-col-md11">
            <div class="layui-card headerCenter">
                <div class="layui-card-header backColor">
                    <i class="layui-icon">&#xe615;</i>
                    用户封停数据列表
                </div>
            </div>
        </div>
    </div>
    <div class="layui-col-md11" style="margin-left: 19px">
        <table id="demo" lay-filter="test"></table>
    </div>
    <input type="hidden" name="userId"/>
</body>
    <script>
        var form;
        var $;
        var table;
        var layer;
        var upload;
        var laydate;
        var createDate;
        var days;
        var user = JSON.parse(localStorage.getItem('user'));
        layui.use(['laydate','form','jquery','table','layer','upload'],function() {
            form = layui.form;
            laydate = layui.laydate;
            $ = layui.jquery;
            table = layui.table;
            layer = layui.layer;
            upload = layui.upload;
            form.on('select(filter)', function(data){
                days = parseInt(data.value); //得到被选中的值
            });

        });
        //重置
        function refresh() {
            $('#myFrom')[0].reset();
            start();
        }

        start();
        //渲染
        function start() {
            $.ajax({
                url:'/UserList/queryUserLockoutList',
                dataType:'json',
                success:function (data) {
                    data = data.data;
                    startTab(data);
                }
            });
        }

        function startTab(data) {
            table.render({
                elem:'#demo',
                page:true,
                data:data,
                cols:[[
                    {checkbox:true},//复选框靠左
                    {title:'序号',width:60,type:'numbers'},
                    {field:"account",title:"用户账号",align:'center'},
                    {field:"nickname",title:"用户昵称",align:'center'},
                    {field:"startDate",title:"账户封停开始时间",align:'center'},
                    {field:"endDate",title:"账户封停结束时间",align:'center'},
                    {field:"days",title:"账户封停天数",align:'center'},
                    {title:"状态",align:'center',templet:function (data) {
                            if(data.status == 1 || data.status == 2){
                                return"<input type='checkbox' value='"+data.userId+"' lay-filter='swi' disabled='disabled' lay-skin='switch' lay-text='正常|停用' checked>";
                            }else{
                                return"<input type='checkbox' value='"+data.userId+"' lay-filter='swi' disabled='disabled' lay-skin='switch' lay-text='正常|停用'>";
                            }
                        }},
                    {field:"reason",title:"封号原因",align:'center'},
                    {title:"操作",align:'center',templet:function (data) {
                            return "<a class='fontColor' onclick='unseal(\""+data.id+"\",\""+data.userId+"\")' href='javascript:;'>解封</a> ";
                        }},
                ]]
            });
        }

        //解封
        function unseal(id,userId) {
            $.ajax({
                url:'/UserList/unseal',
                dataType:'json',
                data:{
                    "id":id,"userId":userId,"createdId":user.userId
                },
                success:function (data) {
                    data = data.data;
                    if(data){
                        layer.msg("解封成功");
                        start();
                    }else{
                        layer.msg("出现问题未能解封成功，请重试");
                    }
                }
            });
        }

        //搜索
        function selProduct() {
            var account = $('input[name = account]').val();
            var nickname = $('input[name = nickname]').val();
            $.ajax({
                url:'/UserList/queryUserLockoutList',
                dataType:'json',
                data:{"account":account,"nickname":nickname,"days":days},
                success:function (data) {
                    data = data.data;
                    startTab(data);
                }
            });
        }

        //高级检索
        function accurate() {
            layer.open({
                type:2,
                title:'高级检索',
                content:'/usermodule/shut-down-users/stop-search.html',
                area:['490px','500px']
            });
        }

        function backOff() {
            var arr = localStorage.getItem("numArr");
            var numArr = arr.split(",");
            numArr.pop();
            window.parent.layui.element.tabChange('tab',numArr[numArr.length - 1]);
            localStorage.setItem("numArr",numArr);
        }

    </script>
</html>